﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CSmcCs;

namespace BankMlt
{
	/// <summary>
	/// Summary description for BankMlt.
	/// </summary>
	public class BankMlt : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox COMMENT;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtDeviceName;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cboTargetAxis;
		private System.Windows.Forms.RadioButton rdoLoop;
		private System.Windows.Forms.RadioButton rdoSingle;
		private System.Windows.Forms.Button btnStop;
		private System.Windows.Forms.Button btnMove;
		private System.Windows.Forms.ComboBox cboBank;
		private System.Windows.Forms.ListBox lstSetList;
		private System.Windows.Forms.CheckBox chk3rdAxis;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Label lblComment;		
		private System.Windows.Forms.Label lbl2ndAxis;
		private System.Windows.Forms.Label lbl3rdAxis;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		int		dwRet;
		short	AxisNo=0;
		short	Id=0;
		short	BankNum=1;
		short	MotionType = (short)CSmcConst.CSMC_SINGLE;
		string	ErrorString;

		CSmc	Smc	= new CSmc();

		public BankMlt()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.rdoLoop = new System.Windows.Forms.RadioButton();
			this.rdoSingle = new System.Windows.Forms.RadioButton();
			this.COMMENT = new System.Windows.Forms.GroupBox();
			this.lblComment = new System.Windows.Forms.Label();
			this.btnExit = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.cboBank = new System.Windows.Forms.ComboBox();
			this.btnStop = new System.Windows.Forms.Button();
			this.btnMove = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.txtDeviceName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.cboTargetAxis = new System.Windows.Forms.ComboBox();
			this.lstSetList = new System.Windows.Forms.ListBox();
			this.chk3rdAxis = new System.Windows.Forms.CheckBox();
			this.lbl2ndAxis = new System.Windows.Forms.Label();
			this.lbl3rdAxis = new System.Windows.Forms.Label();
			this.groupBox2.SuspendLayout();
			this.COMMENT.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoLoop,
																					this.rdoSingle});
			this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox2.Location = new System.Drawing.Point(220, 88);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(88, 88);
			this.groupBox2.TabIndex = 4;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "TYPE";
			// 
			// rdoLoop
			// 
			this.rdoLoop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoLoop.Location = new System.Drawing.Point(10, 56);
			this.rdoLoop.Name = "rdoLoop";
			this.rdoLoop.Size = new System.Drawing.Size(64, 24);
			this.rdoLoop.TabIndex = 8;
			this.rdoLoop.Text = "Loop";
			this.rdoLoop.CheckedChanged += new System.EventHandler(this.rdoLoop_CheckedChanged);
			// 
			// rdoSingle
			// 
			this.rdoSingle.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoSingle.Location = new System.Drawing.Point(10, 24);
			this.rdoSingle.Name = "rdoSingle";
			this.rdoSingle.Size = new System.Drawing.Size(64, 24);
			this.rdoSingle.TabIndex = 7;
			this.rdoSingle.Text = "Single";
			this.rdoSingle.CheckedChanged += new System.EventHandler(this.rdoSingle_CheckedChanged);
			// 
			// COMMENT
			// 
			this.COMMENT.Controls.AddRange(new System.Windows.Forms.Control[] {
																				  this.lblComment});
			this.COMMENT.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.COMMENT.Location = new System.Drawing.Point(8, 184);
			this.COMMENT.Name = "COMMENT";
			this.COMMENT.Size = new System.Drawing.Size(400, 120);
			this.COMMENT.TabIndex = 17;
			this.COMMENT.TabStop = false;
			this.COMMENT.Text = "COMMENT";
			// 
			// lblComment
			// 
			this.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblComment.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblComment.Location = new System.Drawing.Point(8, 20);
			this.lblComment.Name = "lblComment";
			this.lblComment.Size = new System.Drawing.Size(384, 92);
			this.lblComment.TabIndex = 0;
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.Location = new System.Drawing.Point(328, 144);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(80, 32);
			this.btnExit.TabIndex = 0;
			this.btnExit.Text = "EXIT";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboBank,
																					this.btnStop,
																					this.btnMove,
																					this.label3});
			this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox1.Location = new System.Drawing.Point(8, 53);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(196, 123);
			this.groupBox1.TabIndex = 3;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "MOTION";
			// 
			// cboBank
			// 
			this.cboBank.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboBank.Location = new System.Drawing.Point(88, 28);
			this.cboBank.Name = "cboBank";
			this.cboBank.Size = new System.Drawing.Size(80, 23);
			this.cboBank.Sorted = true;
			this.cboBank.TabIndex = 4;
			this.cboBank.SelectedIndexChanged += new System.EventHandler(this.cboBank_SelectedIndexChanged);
			// 
			// btnStop
			// 
			this.btnStop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnStop.Location = new System.Drawing.Point(104, 72);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(80, 32);
			this.btnStop.TabIndex = 6;
			this.btnStop.Text = "STOP";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// btnMove
			// 
			this.btnMove.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnMove.Location = new System.Drawing.Point(8, 72);
			this.btnMove.Name = "btnMove";
			this.btnMove.Size = new System.Drawing.Size(80, 32);
			this.btnMove.TabIndex = 5;
			this.btnMove.Text = "START";
			this.btnMove.Click += new System.EventHandler(this.btnMove_Click);
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(8, 32);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(59, 14);
			this.label3.TabIndex = 2;
			this.label3.Text = "BankNum";
			// 
			// txtDeviceName
			// 
			this.txtDeviceName.AutoSize = false;
			this.txtDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDeviceName.Location = new System.Drawing.Point(93, 16);
			this.txtDeviceName.Name = "txtDeviceName";
			this.txtDeviceName.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
			this.txtDeviceName.Size = new System.Drawing.Size(88, 23);
			this.txtDeviceName.TabIndex = 1;
			this.txtDeviceName.Text = "";
			this.txtDeviceName.TextChanged += new System.EventHandler(this.txtDeviceName_TextChanged);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(190, 21);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(44, 14);
			this.label2.TabIndex = 11;
			this.label2.Text = "AxisNo";
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 21);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(79, 14);
			this.label1.TabIndex = 9;
			this.label1.Text = "Device Name";
			// 
			// cboTargetAxis
			// 
			this.cboTargetAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboTargetAxis.Location = new System.Drawing.Point(238, 17);
			this.cboTargetAxis.Name = "cboTargetAxis";
			this.cboTargetAxis.Size = new System.Drawing.Size(64, 23);
			this.cboTargetAxis.Sorted = true;
			this.cboTargetAxis.TabIndex = 2;
			this.cboTargetAxis.SelectedIndexChanged += new System.EventHandler(this.cboTargetAxis_SelectedIndexChanged);
			// 
			// lstSetList
			// 
			this.lstSetList.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lstSetList.ItemHeight = 15;
			this.lstSetList.Location = new System.Drawing.Point(8, 312);
			this.lstSetList.Name = "lstSetList";
			this.lstSetList.Size = new System.Drawing.Size(400, 124);
			this.lstSetList.Sorted = true;
			this.lstSetList.TabIndex = 6;
			// 
			// chk3rdAxis
			// 
			this.chk3rdAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chk3rdAxis.Location = new System.Drawing.Point(280, 56);
			this.chk3rdAxis.Name = "chk3rdAxis";
			this.chk3rdAxis.Size = new System.Drawing.Size(120, 24);
			this.chk3rdAxis.TabIndex = 5;
			this.chk3rdAxis.Text = "3rdAxisEnable";
			this.chk3rdAxis.CheckedChanged += new System.EventHandler(this.chk3rdAxis_CheckedChanged);
			// 
			// lbl2ndAxis
			// 
			this.lbl2ndAxis.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lbl2ndAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lbl2ndAxis.Location = new System.Drawing.Point(312, 16);
			this.lbl2ndAxis.Name = "lbl2ndAxis";
			this.lbl2ndAxis.Size = new System.Drawing.Size(40, 23);
			this.lbl2ndAxis.TabIndex = 19;
			// 
			// lbl3rdAxis
			// 
			this.lbl3rdAxis.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lbl3rdAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lbl3rdAxis.Location = new System.Drawing.Point(368, 16);
			this.lbl3rdAxis.Name = "lbl3rdAxis";
			this.lbl3rdAxis.Size = new System.Drawing.Size(40, 23);
			this.lbl3rdAxis.TabIndex = 20;
			// 
			// BankMlt
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(416, 444);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.lbl3rdAxis,
																		  this.lbl2ndAxis,
																		  this.chk3rdAxis,
																		  this.lstSetList,
																		  this.groupBox2,
																		  this.COMMENT,
																		  this.btnExit,
																		  this.groupBox1,
																		  this.txtDeviceName,
																		  this.label2,
																		  this.label1,
																		  this.cboTargetAxis});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "BankMlt";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "BankMlt";
			this.Load += new System.EventHandler(this.BankMlt_Load);
			this.groupBox2.ResumeLayout(false);
			this.COMMENT.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new BankMlt());
		}

		private void BankMlt_Load(object sender, System.EventArgs e)
		{
			rdoSingle.Checked = true;
			//-------------
			// Initialize
			//-------------
			AxisNo = 1;

			// AxisNo ComboBox
			for( int i = 0; i < 8;i++ )
			{
				cboTargetAxis.Items.Add(i+1);
			}
			// ComboBox Initialise
			cboTargetAxis.SelectedIndex = AxisNo - 1;
			cboTargetAxis_SelectedIndexChanged(cboTargetAxis, new System.EventArgs());

			BankNum = 1;
			// BankNum ComboBox
			for( int n = 0; n < 4; n++ )
			{
				cboBank.Items.Add(n+1);
			}
			// ComboBox Initialise
			cboBank.SelectedIndex = BankNum - 1;

			string	DeviceName;
			DeviceName="SMC000";
			txtDeviceName.Text = DeviceName;

			dwRet = Smc.WInit(DeviceName, out Id);
	
			bool	bRet;
			for( short m=1;m<=BankNum;m++ )
			{
				bRet = GetMoveParam(m);
				if( bRet == false )break;
			}
		}

		private void DispComment(string func, string msg)
		{
			lblComment.Text = string.Format("{0}: {1}", func, msg);
		}

		private void chk3rdAxis_CheckedChanged(object sender, System.EventArgs e)
		{
			string	wStr = "";
			if( chk3rdAxis.Checked == true )
			{
				wStr = string.Format("{0:d}", AxisNo+2 );
			}
			lbl3rdAxis.Text = wStr;
		}

		private void cboBank_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BankNum = (short)(cboBank.SelectedIndex + 1);
		}

		private void cboTargetAxis_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			AxisNo = (short)(cboTargetAxis.SelectedIndex + 1);
			string	wStr;

			wStr = string.Format("{0:d}", AxisNo+1);
			lbl2ndAxis.Text = wStr;

			if( chk3rdAxis.Checked == true )
			{
				wStr = string.Format("{0:d}", AxisNo+2);
			}
			else
			{
				wStr = "";
			}
			lbl3rdAxis.Text = wStr;
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			Smc.WExit(Id);

			this.Close();
		}

		private void btnMove_Click(object sender, System.EventArgs e)
		{
			bool	bRet;
			//----------------------------------
			// Set parameters to Driver
			//----------------------------------
			bRet = SetBankParam();
			if( bRet == false )return;

			//---------------
			// Ready motion
			//---------------
			dwRet = Smc.WSetBankReady(Id, AxisNo, MotionType);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankReady", ErrorString);
				return;
			}

			lstSetList.Items.Clear();
			for( short n=1;n<=BankNum;n++ )
			{
				GetMoveParam(n);
			}

			//---------------
			// Start Motion
			//---------------
			dwRet = Smc.WMotionStart(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionStart", ErrorString);
				return;
			}
			lblComment.Text = "OK";
		}

		private void btnStop_Click(object sender, System.EventArgs e)
		{
			dwRet = Smc.WMotionStop(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionStop", ErrorString);
				return;
			}
			lblComment.Text = "OK";
		}
		
		private bool SetBankParam() 
		{
			short	InterAxis;
			short	InterType;
			short	Reserved=0;

			//----------------------------
			// Set Bank Number to Driver
			//----------------------------
			dwRet = Smc.WSetBankNumber(Id, AxisNo, BankNum);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankNumber", ErrorString);
				return false;
			}

			//----------------------------
			// Set Interpolation to Driver
			//----------------------------
			InterAxis = (short)((1 << (AxisNo - 1)) +  (1 << AxisNo));
			if( chk3rdAxis.Checked == true )
			{
				InterAxis = (short)(InterAxis + (1 << (AxisNo + 1)));
			}
			InterType = 1; // line interpolation

			for( short BankNo = 1; BankNo <= BankNum; BankNo++ )
			{
				dwRet = Smc.WSetBankInterpolation(Id, AxisNo, BankNo, InterType, InterAxis, Reserved);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetBankInterpolation", ErrorString);
					return false;
				}
			}

			//-------------------------
			// Set Distance to Driver
			//-------------------------
			dwRet = Smc.WSetBankDistance(Id, AxisNo, 1, 500);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankDistance", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankDistance(Id, AxisNo, 2, 1000);
				dwRet = Smc.WSetBankDistance(Id, AxisNo, 3, 1500);
				dwRet = Smc.WSetBankDistance(Id, AxisNo, 4, -3000);
			}

			dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 1), 1, 400);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankDistance", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 1), 2, 900);
				dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 1), 3, 1400);
				dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 1), 4, -2700);
			}
			if( chk3rdAxis.Checked == true )
			{
				dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 2), 1, 300);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetBankDistance", ErrorString);
					return false;
				}
				if( BankNum > 1 )
				{
					dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 2), 2, 800);
					dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 2), 3, 1300);
					dwRet = Smc.WSetBankDistance(Id, (short)(AxisNo + 2), 4, -2400);
				}
			}
			//----------------------------
			// Set StartSpeed to Driver
			//----------------------------
			dwRet = Smc.WSetBankStartSpeed(Id, AxisNo, 1, 1000);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankStartSpeed", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankStartSpeed(Id, AxisNo, 2, 2000);
				dwRet = Smc.WSetBankStartSpeed(Id, AxisNo, 3, 3000);
				dwRet = Smc.WSetBankStartSpeed(Id, AxisNo, 4, 4000);
			}
			//----------------------------
			// Set TargetSpeed to Driver
			//----------------------------
			dwRet = Smc.WSetBankTargetSpeed(Id, AxisNo, 1, 3000);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankTargetSpeed", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankTargetSpeed(Id, AxisNo, 2, 4000);
				dwRet = Smc.WSetBankTargetSpeed(Id, AxisNo, 3, 5000);
				dwRet = Smc.WSetBankTargetSpeed(Id, AxisNo, 4, 6000);
			}
			//----------------------------------
			// Set AccelTime to Driver
			//----------------------------------
			dwRet = Smc.WSetBankAccelTime(Id, AxisNo, 1, 50);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankAccelTime", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankAccelTime(Id, AxisNo, 2, 100);
				dwRet = Smc.WSetBankAccelTime(Id, AxisNo, 3, 150);
				dwRet = Smc.WSetBankAccelTime(Id, AxisNo, 4, 200);
			}
			//----------------------------------
			// Set DecelTime to Driver
			//----------------------------------
			dwRet = Smc.WSetBankDecelTime(Id, AxisNo, 1, 100);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankDecelTime", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankDecelTime(Id, AxisNo, 2, 150);
				dwRet = Smc.WSetBankDecelTime(Id, AxisNo, 3, 200);
				dwRet = Smc.WSetBankDecelTime(Id, AxisNo, 4, 250);
			}
			//-----------------------------
			// Set SSpeed to Driver
			//-----------------------------
			dwRet = Smc.WSetBankSSpeed(Id, AxisNo, 1, 200);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetBankSSpeed", ErrorString);
				return false;
			}
			if( BankNum > 1 )
			{
				dwRet = Smc.WSetBankSSpeed(Id, AxisNo, 2, 400);
				dwRet = Smc.WSetBankSSpeed(Id, AxisNo, 3, 600);
				dwRet = Smc.WSetBankSSpeed(Id, AxisNo, 4, 800);
			}

			//----------------------------------------
			// Other parameter use default parameter
			//----------------------------------------
			return true;
		}
		private bool GetMoveParam(short i)
		{
			string	wStr,wStr1;
			double	dblStartSpeed, dblTargetSpeed, dblAccelTime;
			double	dblDecelTime, dblSSpeed;
			int		lDistance;

			//----------------------------------
			// Get default value of StartSpeed
			//----------------------------------
			dwRet = Smc.WGetBankStartSpeed(Id, AxisNo, i, out dblStartSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankStartSpeed", ErrorString);
				return false;
			}
			wStr = string.Format("BankNo:{0:d} {1:f1}", i, dblStartSpeed);

			//----------------------------------
			// Get default value of TargetSpeed
			//----------------------------------
			dwRet = Smc.WGetBankTargetSpeed(Id, AxisNo, i, out dblTargetSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankTargetSpeed", ErrorString );
				return false;
			}
			wStr1 = string.Format(" {0:f1}", dblTargetSpeed);
			wStr += wStr1;

			//----------------------------------
			// Get default value of AccelRate
			//----------------------------------
			dwRet = Smc.WGetBankAccelTime(Id, AxisNo, i, out dblAccelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankAccelTime", ErrorString);
				return false;
			}
			wStr1 = string.Format(" {0:f1}", dblAccelTime);
			wStr += wStr1;

			//----------------------------------
			// Get default value of DecelRate
			//----------------------------------
			dwRet = Smc.WGetBankDecelTime(Id, AxisNo, i, out dblDecelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankDecelTime", ErrorString);
				return false;
			}
			wStr1 = string.Format(" {0:f1}", dblDecelTime);
			wStr += wStr1;

			//-----------------------------
			// Get default value of SSpeed
			//-----------------------------
			dwRet = Smc.WGetBankSSpeed(Id, AxisNo, i, out dblSSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankSSpeed", ErrorString);
				return false;
			}
			wStr1 = string.Format(" {0:f1}", dblSSpeed);
			wStr += wStr1;

			//----------------------------------
			// Get default value of lDistance
			//----------------------------------
			dwRet = Smc.WGetBankDistance(Id, AxisNo, i, out lDistance);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetBankDistance", ErrorString);
				return false;
			}
			wStr1 = string.Format(" {0:d}", lDistance);
			wStr += wStr1;

			lstSetList.Items.Add(wStr);

			return true;
		}

		private void rdoSingle_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_SINGLE;
		}

		private void rdoLoop_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_LOOP;
		}

		private void txtDeviceName_TextChanged(object sender, System.EventArgs e)
		{
			string wStr = "OK";

			if(Id != -1)
			{
				Smc.WExit(Id);

			}
			wStr = txtDeviceName.Text;
			dwRet = Smc.WInit(wStr, out Id);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWInit", ErrorString);
				Id = -1;
				return ;
			}

			wStr = "OK";
			lblComment.Text = wStr;


		}
	}
}
